import ttkbootstrap as ttk
from ui.navigation import NavigationBar
from ui.card_layout import PDFCardLayout, ImageCardLayout


class MainWindow(ttk.Window):
    def __init__(self):
        super().__init__(themename="litera")
        self.title("")  # 隐藏窗口标题
        self.geometry("1000x700")
        self.resizable(True, True)

        # 主容器
        main_container = ttk.Frame(self)
        main_container.pack(fill="both", expand=True)

        # 标题区域（占满整一行）
        title_frame = ttk.Frame(main_container)
        title_frame.grid(row=0, column=0, columnspan=2, sticky="ew", pady=20)
        ttk.Label(title_frame, text="学长工具集", font=("Helvetica", 25, "bold")).pack()

        # 左侧导航栏
        self.nav_bar = NavigationBar(main_container)
        self.nav_bar.grid(row=1, column=0, sticky="nsew", padx=10)

        # 右侧内容区
        self.content_area = ttk.Frame(main_container)
        self.content_area.grid(row=1, column=1, sticky="nsew", padx=10)

        # 配置行列权重
        main_container.grid_rowconfigure(1, weight=1)
        main_container.grid_columnconfigure(1, weight=1)

        # 初始化卡片布局
        self.pdf_cards = PDFCardLayout(self.content_area)
        self.image_cards = ImageCardLayout(self.content_area)

        # 使用 grid 布局卡片
        self.pdf_cards.grid(row=0, column=0, sticky="nsew")
        self.image_cards.grid(row=0, column=0, sticky="nsew")

        # 默认显示 PDF 工具
        self.show_cards("pdf")

        # 绑定导航栏事件
        self.nav_bar.on_button_click(self.show_cards)

    def show_cards(self, tool_type):
        if tool_type == "pdf":
            self.pdf_cards.grid(row=0, column=0, sticky="nsew")
            self.image_cards.grid_forget()
        elif tool_type == "image":
            self.image_cards.grid(row=0, column=0, sticky="nsew")
            self.pdf_cards.grid_forget()

        # 让 content_area 内部也填满
        self.content_area.grid_rowconfigure(0, weight=1)
        self.content_area.grid_columnconfigure(0, weight=1)
